package com.htfyun;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.OwnerSurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.geometerplus.zlibrary.ui.android.R;

public class HtfyunKdxfMainActivity extends Activity {

    private int count = 0;
    private MyTestView myTestView;
    private Context context;

    private OwnerSurfaceView pwdraw_surface_view;

    Toast toast;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.htfyun_activity_test_kdxf);

        context = this;

        toast = new Toast(context);
        View toastView = LayoutInflater.from(context).inflate(R.layout.toast_layout, null);
        TextView txt = (TextView) toastView.findViewById(R.id.txt);
        
        int paddingLeftDIP = 20;
        int paddingTopDIP = 10;
        int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingLeftDIP, context.getResources().getDisplayMetrics());
        int paddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingTopDIP, context.getResources().getDisplayMetrics());
        txt.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop);
        txt.setShadowLayer(0,0,0, Color.TRANSPARENT);
        txt.setTextColor(Color.BLACK);
        
        toast.setView(toastView);
        
        toast.setDuration(Toast.LENGTH_LONG);
//      
        myTestView = (MyTestView)findViewById(R.id.myView);
//        myTestView.setEinkUpdateMode(View.EINK_DATA_MODE_A2, (short)2);
//
        pwdraw_surface_view = (OwnerSurfaceView) findViewById(R.id.pwdraw_surface_view);
        pwdraw_surface_view.setHostView(myTestView);//, null, false);
        pwdraw_surface_view.setVisibility(View.VISIBLE);
//        pwdraw_surface_view.setDrawObjectType(0);


        ((Button)findViewById(R.id.btn)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                count++;
                myTestView.setText("科大讯飞 " + count);
                
                Toast.makeText(context, "系统Toast", Toast.LENGTH_LONG).show();

//                Intent intent = new Intent(MainActivity.this, TestActivity.class);
//                intent.putExtra("song", "this is my string");
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startActivity(intent);
                
            }
        });
        
        findViewById(R.id.btnClear).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myTestView.clearText();

                toast.show();

//                Intent intent = new Intent(MainActivity.this, TestActivity.class);
//                intent.putExtra("song", "this is my string");
//                intent.putExtra("parcel", new TestParcel(10, "parcel"));
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startActivity(intent);
             
            }
        });
    }
}
